<?php
	$title=$_POST['title'];
	$content=$_POST['content'];
	$cid = $_POST['cid'];
	
	//调用配置文件config.php
	require_once 'config.php';
	//连接数据库 
	$conn = mysql_connect($host, $dbusername,$dbpassword);
	if(!$conn){
		die("连接失败".mysql_error());
	}
	//设置访问数据库的编码
	mysql_query("set names utf8",$conn) or die(mysql_errno());
	//选择数据库
	mysql_select_db($dbname,$conn) or die(mysql_errno());



	//插入文章的标题和内容
	$sql="insert into blog(title,content,cid) value('$title','$content',$cid)";
	$res=mysql_query($sql,$conn);
	//insert操作不需要mysql_free_result($res);



	//取出发表文章的id
	$sql="select id from blog order by time desc limit 0,1";
	$res=mysql_query($sql,$conn);
	$row=mysql_fetch_assoc($res);
	$id=$row['id'];

	mysql_free_result($res);

	mysql_close($conn);

	//跳转到发表文章id的页面
	header("Location: blogPage.php?id=$id");
?>
